package com.zy.mc_module.wheel.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import androidx.annotation.IdRes;

import com.zy.mc_module.R;

import java.util.Objects;

/**
 * 文 件 名：ProtocalDialog
 * 描    述：
 * 作    者：chenhao
 * 时    间：20/6/16
 * 版    权：v1.0
 */
public class ProtocolDialog extends Dialog {
    private Context mContext;
    private View view;
    protected int layoutId;


    public ProtocolDialog(Context context, int layoutId) {
        super(context, R.style.BottomDialog);
        this.mContext = context;
        this.layoutId = layoutId;
        this.view = LayoutInflater.from(context).inflate(layoutId, null, false);
    }

    public ProtocolDialog(Context context, View view) {
        super(context, R.style.BottomDialog);
        this.view = view;
        this.layoutId = 0;
        this.mContext = context;
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        view.setMinimumWidth(10000);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(view);
        //初始化视图
        initView(view);
    }

    public <T extends View> T getView(@IdRes int id) {
        return view.findViewById(id);
    }

    private void initView(View view) {

    }

    public ProtocolDialog showBottom() {
        Objects.requireNonNull(getWindow()).setGravity(Gravity.BOTTOM); //显示在底部
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        return this;
    }

    @Override
    public void dismiss() {
        if (null != this && this.isShowing()) {
            super.dismiss();
        }
    }
}
